package com.bawei.ffmpeg;

import io.microshow.rxffmpeg.RxFFmpegCommandList;
import io.microshow.rxffmpeg.RxFFmpegInvoke;
import io.microshow.rxffmpeg.RxFFmpegSubscriber;

/**
 * Author: Jason Zhang
 * Date: 2024/10/9
 * Desc:
 */
public class FFmpegUtil {

    /**
     *
     * @param resourcePath 原视频文件路径
     * @param targetPath 目标视频文件路径
     * @param subscriber 订阅者
     */
    public static void runFFmpegCommands(String resourcePath, String targetPath, RxFFmpegSubscriber subscriber){
        RxFFmpegCommandList cmdList = new RxFFmpegCommandList();
        cmdList.append("-y");
        cmdList.append("-i");
        cmdList.append(resourcePath);
        cmdList.append("-vf");
        cmdList.append("boxblur=25:5");
        cmdList.append("-preset");
        cmdList.append("superfast");
        cmdList.append(targetPath);

        String[] commands = cmdList.build();
        //执行FFmpeg命令
        RxFFmpegInvoke.getInstance().runCommandRxJava(commands).subscribe(subscriber);
    }


    /**
     * 视频转图片
     * ffmpeg -y -i /storage/emulated/0/1/input.mp4 -f image2 -r 1 -q:v 10 -preset superfast /storage/emulated/0/1/%3d.jpg
     */
    public static void runVideoToJpg(String videoPath, String targetPath, RxFFmpegSubscriber subscriber){
        RxFFmpegCommandList cmdList = new RxFFmpegCommandList();
        cmdList.append("-y");
        cmdList.append("-i");
        cmdList.append(videoPath);
        cmdList.append("-f");
        cmdList.append("image2");
        cmdList.append("-r");
        cmdList.append("1");
        cmdList.append("-q:v");
        cmdList.append("10");
        cmdList.append("-preset");
        cmdList.append("superfast");
        cmdList.append(targetPath);

        String[] commands = cmdList.build();

        //执行FFmpeg命令
        RxFFmpegInvoke.getInstance().runCommandRxJava(commands).subscribe(subscriber);

    }



}
